package com.wgo.precise.client.ui.view.projecttree;

import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;

import com.wgo.precise.client.ui.controller.RequirementPlugin;
import com.wgo.precise.client.ui.model.CategoryWrapper;
import com.wgo.precise.client.ui.model.NodeParent;
import com.wgo.precise.client.ui.model.PropertySetWrapper;

import remato.domain.common.Category;

/**
 * 
 * @author Petter L. H. Eide
 * @version $Id: CreateCategoryAction.java,v 1.2 2006-01-30 21:52:33 petterei Exp $
 */
public class CreateCategoryAction extends CreateAction<CategoryWrapper, NodeParent> {

    public CreateCategoryAction(NodeParent item) {
        super(createText(Category.class.getSimpleName()), item, PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_FOLDER));
    }

    /**
     * @see com.wgo.precise.client.ui.view.projecttree.CrudAction#run()
     */
    @Override
    public void run() {
        Category domainCategory = RequirementPlugin.getInstance().getSession().getDomainSession().createConcept(Category.class);
        CategoryWrapper item = RequirementPlugin.getInstance().getSession().getWrapperFactory().getWrapper(domainCategory);
        item.setParent(getItem());
        if (getItem() instanceof CategoryWrapper) {
        	for (PropertySetWrapper definitionSetWrapper : ((CategoryWrapper)getItem()).getPropertyDefinitionSets()) {
				item.addPropertyDefinitionSetWrapper(definitionSetWrapper);
			}
        }
        setNewItem(item);
        super.run();
    }

}
